#include <EXTERN.h>
#include <perl.h>

int main(int argc, char** argv, char** env) {
   PerlInterpreter *my_perl;
   char *switches[] = {"", "-e", "0"};
   SV* joined;
   SV* stack[4];

   my_perl = perl_alloc();
   perl_construct(my_perl);
   perl_parse(my_perl, NULL, 3, switches, (char**)NULL);
   perl_run(my_perl);

   /* place a dummy SV on top of the stack */
   stack[0] = &PL_sv_undef;

   /* the strings we want to join */
   stack[1] = newSVpv("one", 0);
   stack[2] = newSVpv("two", 0);
   stack[3] = newSVpv("three", 0);

   /* this will hold the result */
   joined = &PL_sv_undef;

   do_join(joined, newSVpv(", ", 0), stack, stack+3);

   printf("and the result is: '%s'\n", SvPV(joined, PL_na));

   perl_destruct(my_perl);
   perl_free(my_perl);
}
